﻿Imports DataObject
Imports BusinessObject
Imports Microsoft.ApplicationBlocks.Data

Public Class frmChucDanhDetail

    Private ptyChucDanh As New ChucDanh
    Private oChucDanh As New BusChucDanh
    Private oFunction As New hDCommonFunction

    Private Sub frmChucDanhDetail_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If (Me.eActionMode = EditMode.AddNew) Then
            Me.Text = "Thêm mới chức danh"
        Else
            Me.Text = "Sửa chức danh"
        End If
        txtMaChucVu.Focus()
        DataBindingToControl(GroupBox1)
    End Sub

    Public Overrides Function ValidateData() As Boolean
        If txtMaChucVu.Text = "" Then
            MessageBox.Show("Mã chức vụ không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtMaChucVu.Focus()
            Return False
        End If
        If txtTenChucVu.Text = "" Then
            MessageBox.Show("Tên chức vụ không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtTenChucVu.Focus()
            Return False
        End If
        Return True
    End Function

    Protected Overrides Function SaveDictionary() As Boolean
        Dim bResult As Boolean = False
        Try
            ptyChucDanh.MaChucDanh = txtMaChucVu.Text
            ptyChucDanh.TenChucDanh = txtTenChucVu.Text
            ptyChucDanh.DienGiai = txtDienGiai.Text
            ptyChucDanh.HoatDong = chkHoatDong.CheckedValue
            If (eActionMode = EditMode.AddNew) Then
                oChucDanh.InsertChucDanh(sConn, ptyChucDanh)
            ElseIf (eActionMode = EditMode.Edit) Then
                ptyChucDanh.SoChucDanh = RowDetail.Item("SoChucDanh")
                oChucDanh.UpdateChucDanh(sConn, ptyChucDanh)
            End If
            bResult = True
        Catch ex As Exception
            MessageBox.Show(ex.ToString, "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
            bResult = False
        End Try
        Return bResult
    End Function

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

    End Sub
End Class
